package cn.royan.fl 
{
	import cn.royan.fl.interfaces.IRequest;
	import cn.royan.fl.utils.builders.ConfigBuilder;
	import cn.royan.fl.values.ClientConfig;
	import cn.royan.fl.controllers.commands.StartSocketCommand;
	import cn.royan.fl.controllers.commands.PacketReceiveCommand;
	import cn.royan.fl.controllers.commands.PacketDispatchCommand;
	import flash.utils.Dictionary;
	import org.puremvc.as3.patterns.facade.Facade;
	
	/**
	 * ...
	 * @author RoYan
	 */
	public class SocketFacade extends Facade
	{
		public static const START_SOCKET:String		= "startSocket";
		public static const PACKET_RECEIVE:String	= "packetReceive";
		public static const PACKET_DISPATCH:String	= "packetDispatch";
		
		private static var instance:SocketFacade;
		
		public static function getInstance():SocketFacade
		{
			if ( instance == null ) instance = new SocketFacade();
			return instance as SocketFacade;
		}
		
		public function startUp( host:String = "127.0.0.1", port:int = 80, client:ClientSocket = null ):void
		{
			var dic:Dictionary 	= new Dictionary();
				dic["host"] 	= host;
				dic["port"] 	= port;
				dic["client"] 	= client;
			
			var builder:ConfigBuilder = new ConfigBuilder( dic );
				
			sendNotification( START_SOCKET, builder.build().getResult() );
		}
		
		override protected function initializeController():void 
		{
			super.initializeController();
			registerCommand( START_SOCKET, 		StartSocketCommand );
			registerCommand( PACKET_RECEIVE,  	PacketReceiveCommand );
			registerCommand( PACKET_DISPATCH,  PacketDispatchCommand );
		}
	}

}